cmake_minimum_required(VERSION 3.13)
project(examples VERSION 1.0.0 LANGUAGES C CXX)

# This project can use C11, but will gracefully decay down to C89.
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED OFF)
set(CMAKE_C_EXTENSIONS OFF)

# This project requires C++11.
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

if(WIN32)
    add_definitions(-DWIN32_LEAN_AND_MEAN)
    add_definitions(-DUNICODE -D_UNICODE)
    add_definitions(-D_CRT_SECURE_NO_WARNINGS)
    add_definitions(-D_WINSOCK_DEPRECATED_NO_WARNINGS)
else()
    add_definitions(-D_FILE_OFFSET_BITS=64)
endif()

if(WIN32)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
    set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
    set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
    set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /MT")
    set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} /MT")
    set(BASELIB_LIBRARIES wsock32 ws2_32)
else()
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
    set(BASELIB_LIBRARIES m pthread)
endif()

add_executable(client ${PROJECT_SOURCE_DIR}/src/client.cc)
add_executable(server ${PROJECT_SOURCE_DIR}/src/server.cc)

add_executable(uring_client ${PROJECT_SOURCE_DIR}/src/uring_client.cc)
add_executable(uring_server ${PROJECT_SOURCE_DIR}/src/uring_server.cc)

target_link_libraries(client ${BASELIB_LIBRARIES})
target_link_libraries(server ${BASELIB_LIBRARIES})
target_link_libraries(uring_client ${BASELIB_LIBRARIES} uring)
target_link_libraries(uring_server ${BASELIB_LIBRARIES} uring)
